<template>
  <div>
    <div class="q1">上级考点:{{ parentName }}</div>
    <el-form class="el-form" v-model="form">
      <el-form-item label="考点名称" label-width="100px">
        <el-input
          class="inp"
          v-model="form.name"
          maxlength="15"
          placeholder="考点名称最多输入15个字"
        ></el-input>
      </el-form-item>
        <el-input
          type="textarea"
          :rows="2"
          placeholder="备注最多输入500个字"
          maxlength="500"
          v-model="form.description"
        >
        </el-input>
      </el-form-item>
      <el-button @click="fan">返回</el-button>
      <el-button type="primary" @click="submit">保存并返回</el-button>
    </el-form>
  </div>
</template>
<script>
import axios from "axios";
export default {
  components: {},
  data() {
    return {
      parentName: this.$route.query.parentName || "顶级分类",
      form: {
        id: this.$route.query.id || 0, // 要修改的记录的ID，0：添加,非0代表是修改
        parent_id: 0, // 如果没传就是0，否则就用传的值
        name: "",
        description: "",
      },
    };
  },
  mounted() {
    // 编辑
    axios.get("/exam/point/" + this.form.id).then((res) => {
      this.form.name = res.data.data.name;
      this.form.description = res.data.data.description;
    });
  },
  methods: {
    submit() {
      if (this.form.id) {
        // 编辑
        axios.put("/exam/point/" + this.form.id, this.form).then((res) => {
          console.log(res);
          this.$message.success("修改成功");
          this.$router.push({ name: "QuestionQuestionCheckPointManage" });
        });
      } else {
        // 添加
        axios.post("/exam/point", this.form).then(() => {
          this.$message.success("添加成功");
          this.$router.push({ name: "QuestionQuestionCheckPointManage" });
        });
      }
    },
    fan() {
      this.$router.push({ name: "QuestionQuestionCheckPointManage" });
    },
  },
  computed: {},
  watch: {},
};
</script>
<style scoped>
.q1 {
  float: left;
  margin-top: 20px;
}
.el-form {
  float: left;
  margin-top: 50px;
  margin-left: -120px;
}
.inp {
  width: 200px;
  float: left;
}
</style>
